package com.sto.stoapp.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.entity.FunctionEntity;

/**
 * 单一的适配器模式
 * 
 * @author mgf
 * 
 */
public class SoleAdapter extends BaseAdapter {

	private Context context;

	private List<FunctionEntity> resList;

	/**
	 * 构造函数
	 * 
	 * @param context
	 *            上下文
	 * @param resList
	 *            资源ID
	 */
	public SoleAdapter(Context context, List<FunctionEntity> resList) {
		this.context = context;
		this.resList = resList;
	}

	@Override
	public int getCount() {
		return resList == null ? 0 : resList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return resList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		Holder holder;
		if (view == null) {
			holder = new Holder();
			view = LayoutInflater.from(context).inflate(
					R.layout.sto_sole_adapter, null);
			holder.numberId = (TextView) view.findViewById(R.id.number_id);
			holder.resText = (TextView) view.findViewById(R.id.res_test);
			view.setTag(holder);
		} else {
			holder = (Holder) view.getTag();
		}
		int count = position + 1;
		holder.numberId.setText(count + "、");
		holder.resText.setText(resList.get(position).getTitle());
		return view;
	}

	class Holder {
		TextView numberId;
		TextView resText;
	}
}
